home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / TEST_LIS.C < prev    next >
C/C++ Source or Header  |  1992-08-14  |  37KB  |  1,108 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12. // Updated: JAM 08/14/92 -- modernized template syntax, remove macro hacks
  13. // Updated: JAM 08/14/92 -- changed counter n from int->long
  14.  
  15. #include <test.h>
  16. #include <cool/List.h>
  17. #include <cool/Vector.h>
  18. #include <cool/Timer.h>
  19.  
  20. #include <cool/List.C>
  21. #include <cool/Vector.C>
  22.  
  23. // *****************
  24. // List of int tests
  25. // *****************
  26.  
  27. int my_compare_int(const int& t1, const int& t2) {
  28.   return ((t1 < t2) ? -1 : 1);
  29. }
  30.  
  31. void list_int_op_test1() {
  32.   
  33.   CoolList<int> ltemp1;
  34.   CoolList<int> ltemp2;
  35.  
  36.   // CoolList l0 is ().
  37.   CoolList<int> l0;
  38.   TEST("CoolList<int> l0", 1, 1);
  39.  
  40.   // CoolList l1(3) is (3).
  41.   CoolList<int> l1(3);
  42.   TEST("CoolList<int> l1(3)", 1, 1);
  43.  
  44.   // CoolList l2(2,l1) is (2 3).
  45.   CoolList<int> l2(2,l1);
  46.   TEST("CoolList<int> l2(2,l1)", 1, 1);
  47.  
  48.   // CoolList l3(1,l2) is (1 2 3).
  49.   CoolList<int> l3(1,l2);
  50.   TEST("CoolList<int> l3(1,l2)", 1, 1);
  51.  
  52.   // CoolList l4(3,1,2,3) is (1 2 3).
  53.   CoolList<int> l4(3,1,2,3);
  54.   TEST("CoolList<int> l4(3,1,2,3)", 1, 1);
  55.  
  56.   CoolList<int> l41(1, 0);
  57.   TEST("CoolList<int> l41(1, 0)", 
  58.        (l41[0]==0 && l41.length()==1), TRUE);
  59.   CoolList<int> l42(2, 0, 1);
  60.   TEST("CoolList<int> l42(2, 0, 1)", 
  61.        (l42[0]==0 && l42[1]==1 && l42.length()==2), TRUE);
  62.   CoolList<int> l43(3, 0, 1, 2);
  63.   TEST("CoolList<int> l43(3, 0, 1, 2)", 
  64.        (l43[0]==0 && l43[1]==1 && l43[2]==2 && l43.length()==3), TRUE);
  65.  
  66.  
  67.   // CoolList l5(l4) is (1 2 3).
  68.   CoolList<int> l5(l4);
  69.   TEST("CoolList<int> l5(l4)", 1, 1);
  70.   TEST("l3 == l4", l3==l4, TRUE);
  71.  
  72.   TEST("l5[2]", l5[2]==3 && l5.value()==3, TRUE);
  73. //  TEST("l5[-1]", l5[-1], ERROR);
  74. //  TEST("l5[3]", l5[3], ERROR);
  75.   TEST("l5.get(1)", l5.get(1)==2, TRUE);
  76.   TEST_RUN("l5[1]=43", l5[1]=43, l5[1]==43, TRUE);
  77.   TEST_RUN("l5.put(55,1)", l5.put(55,1), l5.get(1)==55, TRUE);
  78.   // l5 is (1 55 3);
  79.   TEST_RUN("l5.tail(ltemp1)", l5.tail(ltemp1),
  80.        (ltemp1.length()==2 && ltemp1[0]==55 && ltemp1[1]==3), TRUE);
  81.   TEST_RUN("l5.tail(ltemp1,0)", l5.tail(ltemp1,0),
  82.        (ltemp1.length()==3 && ltemp1[0]==1 && ltemp1[1]==55 
  83.         && ltemp1[2]==3),
  84.        TRUE);
  85.   TEST_RUN("l5.tail(ltemp1,3)", l5.tail(ltemp1,3), ltemp1.is_empty(), TRUE);
  86.   TEST_RUN("l5.tail(ltemp1,5)", l5.tail(ltemp1,5), ltemp1.is_empty(), TRUE);
  87.  
  88.   // l5 is (1 55 3);
  89.   TEST_RUN("l5.last(ltemp1, 0)", l5.last(ltemp1, 0), ltemp1.is_empty(), TRUE);
  90.   TEST_RUN("l5.last(ltemp1)", l5.last(ltemp1),
  91.        (ltemp1.length()==1 && ltemp1[0]==3), TRUE);
  92.   TEST_RUN("l5.last(ltemp1,2)", l5.last(ltemp1,2),
  93.        (ltemp1.length()==2 && ltemp1[0]==55 && ltemp1[1]==3),
  94.        TRUE);
  95.   TEST_RUN("l5.last(ltemp1,3)", l5.last(ltemp1,3),
  96.        (ltemp1.length()==3 && ltemp1[0]==1 && ltemp1[1]==55 
  97.         && ltemp1[2]==3),
  98.        TRUE);
  99.   TEST_RUN("l5.last(ltemp1,5)", l5.last(ltemp1,5), ltemp1.is_empty(), TRUE);
  100.   // l2 is (2 3)
  101.   TEST("l2.is_empty()", l2.is_empty(), FALSE);
  102.   // l3 is (1 2 3)
  103.   TEST("l3.length()", l3.length()== 3, TRUE);
  104. }
  105.  
  106. void list_int_op_test2() {
  107.   
  108.   CoolList<int> ltemp1;
  109.   CoolList<int> ltemp2;
  110.  
  111.   ltemp1 = CoolList<int>(4,11,22,33,44);
  112.   CoolList<int> l6;
  113.  
  114.   TEST_RUN("l6.but_last(ltemp2, 0)", l6.copy(ltemp1);  l6.but_last(ltemp2, 0),
  115.        (ltemp2.length()==4 && ltemp2[0]==11 && ltemp2[1]==22 
  116.         && ltemp2[2]==33 && ltemp2[3]==44),
  117.        TRUE);
  118.  
  119.   // l6 is now (11 22 33 44)
  120.   TEST_RUN("l6.but_last(ltemp2)", l6.but_last(ltemp2),
  121.        (ltemp2.length()==3 && ltemp2[0]==11 && ltemp2[1]==22 
  122.         && ltemp2[2]==33),
  123.        TRUE);
  124.   TEST_RUN("l6.but_last(ltemp2, 2)", l6.but_last(ltemp2, 2),
  125.        (ltemp2.length()==2 && ltemp2[0]==11 && ltemp2[1]==22),
  126.        TRUE);
  127.   TEST_RUN("l6.but_last(ltemp2, 4)", l6.but_last(ltemp2, 4), 
  128.        (ltemp2.length()==0), TRUE);
  129.   TEST_RUN("l6.but_last(ltemp2, 5)", l6.but_last(ltemp2, 5),
  130.        (ltemp2.length()==0), TRUE);
  131.  
  132.   TEST_RUN("l6.clear()", l6.clear(), (l6.length()==0), TRUE); 
  133.   // l6 is now ()
  134.   TEST("l6.is_empty()", l6.is_empty(), TRUE);
  135.   TEST("l6.length()", l6.length()==0, TRUE);
  136.  
  137.   // l6 is (11 22 33 44)
  138.   TEST_RUN("l6.position(33)", l6.copy(ltemp1), 
  139.        (l6.position(33)==2 && l6.value()==33), TRUE);
  140.   TEST("l6.position(2)", l6.position(2)==-1, TRUE);
  141. }
  142.  
  143. void list_int_op_test3() {
  144.   int temp;
  145.   CoolList<int> ltemp1;
  146.   CoolList<int> ltemp2;
  147.   CoolList<int> l0;
  148.   CoolList<int> l1(3);                // CoolList l1 is (3).
  149.   CoolList<int> l2(2,l1);                // CoolList l2 is (2 3).
  150.   CoolList<int> l3(1,l2);                // CoolList l3 is (1 2 3).
  151.   CoolList<int> l4(3,1,55,3);            // CoolList l4 is (1 55 3).
  152.   CoolList<int> l5(l4);                // CoolList l5 is (1 2 3).
  153.   CoolList<int> l6(4, 11, 22, 33, 44);        // CoolList l6 is (11 22 33 44)
  154.  
  155.   CoolList<int> l9;
  156.   TEST_RUN("l9.copy(l4)", l9.copy(l4), (l4==l9), TRUE);
  157.   TEST_RUN("l9 = l4", l9 = l4, (l4==l9), TRUE);
  158.  
  159.   // l6 is (11 22 33 44)
  160.   ltemp1 = CoolList<int>(4,44,33,22,11);
  161.   TEST_RUN("l6.reverse()", l6.reverse(), (l6==ltemp1), TRUE);
  162.  
  163.   // l6 is (44 33 22 11)
  164.   TEST_RUN("l6.push_end(66)", l6.push_end(66), 
  165.        (l6.length()==5 && l6[4]==66 && l6.value()==66),
  166.        TRUE);
  167.   TEST_RUN("l6.push(77)", l6.push(77), 
  168.        (l6.length()==6 && l6[0]==77 && l6.value()==77), TRUE);
  169.   TEST_RUN("l6.push_new(88)", l6.push_new(88), 
  170.        (l6.length()==7 && l6[0]==88 && l6.value()==88),
  171.        TRUE);
  172.   TEST_RUN("l6.push_new(22)", l6.push_new(22), 
  173.        (l6.length()==7 && l6[0]==88), TRUE);
  174.   TEST("l6.pop()", (l6.pop(temp), temp), 88);
  175.  
  176.   // l6 is (77 44 33 22 11 66)
  177.   // l2 is (2 3)
  178.   // l4 is (1 55 3)
  179.  
  180.   // l6 is now (77 44 33 22 11 66 2 3)
  181.   TEST_RUN("l6.append(l2)", l6.append(l2),
  182.        (l6.value()==2 && l6.length()==8 && l6[6]==2 && l6[7]==3), TRUE);
  183.  
  184.   // l6 is now (1 55 3 77 44 33 22 11 66 2 3)
  185.   TEST_RUN("l6.prepend(l4)", l6.prepend(l4),
  186.        (l6.value()==1 && l6.length()==11 && l6[0]==1 && l6[1]==55 
  187.         && l6[2]==3),
  188.        TRUE);
  189.  
  190.   TEST_RUN("l6.set_tail(l2, 14)", ltemp1.copy(l6), l6.set_tail(l2,14), FALSE);
  191.   TEST("l6.set_tail(l2, 14) ==", l6==ltemp1, TRUE);
  192.   ltemp2 = CoolList<int>(6,1,55,3,77,2,3);
  193.   TEST("l6.set_tail(l2,4)", l6.set_tail(l2,4), TRUE);
  194.   TEST("l6.set_tail(l2,4) ==", (l6==ltemp2), TRUE);
  195.   TEST("l6.set_tail(l2,4) value", l6.value(), 2);
  196.   TEST_RUN("l6.set_tail(l2)", l6.set_tail(l2),
  197.        (l6.value()==2 && l6.length()==3 && l6[0]==1 && l6[1]==2 
  198.         && l6[2]==3),
  199.        TRUE);
  200.   TEST_RUN("l6.set_tail(l2,0)", l6.set_tail(l2,0),
  201.        (l6.value()==2 && l6.length()==2 && l6[0]==2 && l6[1]==3), TRUE);
  202.  
  203. }
  204.  
  205. void list_int_op_test4() {
  206.   CoolList<int> ltemp1;
  207.   CoolList<int> ltemp2;
  208.  
  209.   ltemp1 = CoolList<int>(4,44,33,22,11);
  210.  
  211.   CoolList<int> l8(5,11,22,33,44,55);
  212.   ltemp1.copy(l8);
  213.   ltemp2 = CoolList<int>(4,11,22,33,55);
  214.   TEST_RUN("l8.remove(77)", l8.remove(77), (l8==ltemp1), TRUE);
  215.   TEST_RUN("l8.remove(44)", l8.remove(44), (l8==ltemp2 && l8.value()==55),
  216.        TRUE);
  217.  
  218.   CoolList<int> l11(7,11,22,33,11,22,33,44,11,11);
  219.   ltemp1 = CoolList<int>(4,11,22,33,44);
  220.   l11.remove_duplicates();
  221.   TEST_RUN("l11.remove_duplicates()", l11.remove_duplicates(), (l11==ltemp1),
  222.        TRUE);
  223.  
  224.   // l8 is now (11 22 33 55)
  225.   ltemp1.copy(l8);
  226.   ltemp2 = CoolList<int>(4,11,55,33,55);
  227.   TEST_RUN("l8.replace(66,22)", l8.replace(66,22), (l8==ltemp1), TRUE);
  228.   TEST_RUN("l8.replace(22,55)", l8.replace(22,55), 
  229.        (l8==ltemp2 && l8.value()==55), TRUE);
  230.  
  231.   ltemp1.copy(l8);
  232.   ltemp2 = CoolList<int>(4,11,22,33,22);
  233.   TEST_RUN("l8.replace_all(66,22)", l8.replace_all(66,22), (l8==ltemp1), TRUE);
  234.   TEST_RUN("l8.replace_all(55,22)", l8.replace_all(55,22), (l8==ltemp2), TRUE);
  235.  
  236.  
  237.   // l8 is now (11 22 33 22)
  238.   ltemp1.copy(l8);
  239.   ltemp2 = CoolList<int>(5,11,22,111,33,22);
  240.   TEST_RUN("l8.insert_after(111,44)", l8.insert_after(111,44), (l8==ltemp1),
  241.        TRUE);
  242.   TEST_RUN("l8.insert_after(111,22)", l8.insert_after(111,22), 
  243.        (l8==ltemp2 && l8.value()==111), TRUE);
  244.  
  245.   TEST_RUN("l8.insert_before(222,44)", 
  246.        ltemp1.copy(l8); l8.insert_before(222,44), 
  247.        (l8==ltemp1), TRUE);
  248.   ltemp2 = CoolList<int>(6,11,222,22,111,33,22);
  249.   TEST_RUN("l8.insert_before(222,22)", l8.insert_before(222,22),
  250.        (l8==ltemp2 && l8.value()==222), TRUE);
  251.   ltemp2 = CoolList<int>(7,333,11,222,22,111,33,22);
  252.   TEST_RUN("l8.insert_before(333,11)", l8.insert_before(333,11),
  253.        (l8==ltemp2 && l8.value()==333), TRUE);
  254. }
  255.  
  256. void list_int_sort_test() {
  257.  
  258.   CoolList<int> l1(4,6,66,22,222);
  259.   CoolList<int> l2(4,61,12,222,666);
  260.   CoolList<int> l3(4,7,51,77,24);
  261.   CoolList<int> l4(2,22,33);
  262.   CoolList<int> ltemp1;
  263.  
  264.   ltemp1 = CoolList<int>(8,6,61,12,66,22,222,222,666);
  265.   TEST_RUN("l1.merge(l2,&my_compare_int)", l1.merge(l2,&my_compare_int), 
  266.        (l1==ltemp1), TRUE);
  267.  
  268.   ltemp1 = CoolList<int>(6,22,33,61,12,222,666);
  269.   TEST_RUN("l4.merge(l2,&my_compare_int)", l4.merge(l2,&my_compare_int), 
  270.        (l4==ltemp1), TRUE);
  271.  
  272.   ltemp1 = CoolList<int>(4,12,61,222,666);
  273.   TEST_RUN("l2.sort(&my_compare_int)", l2.sort(&my_compare_int), (l2==ltemp1),
  274.        TRUE);
  275.  
  276.   ltemp1 = CoolList<int>(4,7,24,51,77);
  277.   TEST_RUN("l3.sort(&my_compare_int)", l3.sort(&my_compare_int), (l3==ltemp1),
  278.        TRUE);
  279. }
  280.  
  281. void list_int_io_test() {
  282.  
  283.   // ** an automated test would get input from file, rather than cin **
  284.   CoolList<int> input_list;
  285. //  cout << "\nTesting operator>> for CoolList<int>.";
  286. //  cout << "\nExample of CoolList<int> is (1 2 3).";
  287. //  cout << "\nPlease enter a CoolList<int> structure: ";
  288. //  cin >> input_list;
  289. //  cout << "\nInput_list is now set to: " << input_list << ".\n";
  290.  
  291. }
  292.  
  293.  
  294. void list_int_set_test1() {
  295.   CoolList<int> ltemp1;
  296.   CoolList<int> l1;
  297.   CoolList<int> l2(4,11,22,33,44);
  298.   CoolList<int> l3(2,22,33);
  299.   CoolList<int> l4(5,11,22,33,44,55);
  300.  
  301.   TEST("l2.find(33)", (l2.find(33) && l2.value()==33), TRUE);
  302.   TEST("l2.find(2)", l2.find(2), FALSE);
  303.  
  304.   TEST("l2.search(l3)", (l2.search(l3) && l2.value()==22), TRUE);
  305.   TEST("l2.search(l1)", l2.search(l1), FALSE);
  306.   TEST("l2.search(l4)", l2.search(l4), FALSE);
  307.   TEST("l4.search(l2)", (l4.search(l2) && l4.value()==11), TRUE);
  308.   TEST("l1.search(l2)", l1.search(l2), FALSE);
  309.  
  310.   TEST_RUN("l2.member(ltemp1, 22)", l2.member(ltemp1, 22),
  311.        (ltemp1.length()==3, ltemp1[0]==22 && ltemp1[1]==33, ltemp1[2]==44
  312.         && l2.value()==22),
  313.        TRUE);
  314.   TEST_RUN("l2.member(ltemp1, 44)", l2.member(ltemp1, 44),
  315.        (ltemp1.length()==1 && ltemp1[0]==44 && l2.value()==44),
  316.        TRUE);
  317.   TEST_RUN("l2.member(ltemp1, 3)", l2.member(ltemp1, 3), (ltemp1.length()==0),
  318.        TRUE);
  319.  
  320.   TEST_RUN("l2.sublist(ltemp1, l3)", l2.sublist(ltemp1, l3),
  321.        (ltemp1.length()==3 && ltemp1[0]==22, ltemp1[1]==33, ltemp1[2]==44
  322.         && l2.value()==22),
  323.        TRUE);
  324.   TEST_RUN("l2.sublist(ltemp1, l1)", l2.sublist(ltemp1, l1),
  325.        (ltemp1.length()==0), TRUE);
  326.   TEST_RUN("l2.sublist(ltemp1, l4)", l2.sublist(ltemp1, l4), 
  327.        (ltemp1.length()==0), TRUE);
  328.   TEST_RUN("l4.sublist(ltemp1, l2)", l4.sublist(ltemp1, l2), 
  329.        (ltemp1==l4 && l4.value()==11), TRUE);
  330.   TEST_RUN("l1.sublist(ltemp1, l2)", l1.sublist(ltemp1, l2), 
  331.        (ltemp1.length()==0), TRUE);
  332. }
  333.  
  334. void list_int_set_test2() {
  335.   CoolList<int> ltemp1;
  336.   CoolList<int> l5(12,1,55,3,88,77,44,33,22,11,66,2,3);
  337.   CoolList<int> l6(5,11,66,111,33,55);
  338.  
  339.   ltemp1 = CoolList<int>(4,55,33,11,66);
  340.   TEST_RUN("l5.set_intersection(l6)", l5.set_intersection(l6), (l5==ltemp1), TRUE);
  341.  
  342.   ltemp1 = CoolList<int>(5,111,55,33,11,66);
  343.   TEST_RUN("l5.set_union(l6)", l5.set_union(l6), (l5==ltemp1), TRUE);
  344.  
  345.   TEST_RUN("l5.set_difference(l6)", ltemp1.clear(); l5.set_difference(l6), 
  346.        (l5==ltemp1), TRUE);
  347.  
  348.   ltemp1 = CoolList<int>(5,11,66,111,33,55);
  349.   TEST_RUN("l5.set_xor(l6)", l5.set_xor(l6), (l5==ltemp1), TRUE);
  350.  
  351. }
  352.  
  353. void list_int_set_test3() {
  354.   CoolList<int> ltemp1;
  355.   CoolList<int> l7(2,2,3);
  356.   CoolList<int> l8(3,1,2,3);
  357.   CoolList<int> l9 = l7 + l8;
  358.   CoolList<int> l10(3,4,5,6);
  359.   CoolList<int> l11(12,1,55,3,88,77,44,33,22,11,66,2,3);
  360.   CoolList<int> l12(5,11,66,111,33,55);
  361.   CoolList<int> l13;
  362.  
  363.   ltemp1 = CoolList<int>(5,2,3,1,2,3);
  364.   TEST("l9 = l7 + l8", (l9==ltemp1), TRUE);
  365.  
  366.   ltemp1 = CoolList<int>(5,2,3,4,5,6);
  367.   TEST_RUN("l7 += l10", l7 += l10, (l7==ltemp1), TRUE);
  368.  
  369.   ltemp1 = CoolList<int>(4,55,33,11,66);
  370.   TEST_RUN("l11 &= l12", l11 &= l12, (l11==ltemp1), TRUE);
  371.  
  372.   ltemp1 = CoolList<int>(5,111,55,33,11,66);
  373.   TEST_RUN("l11 |= l12", l11 |= l12, (l11==ltemp1), TRUE);
  374.  
  375.   TEST_RUN("l11 -= l12", ltemp1.clear(); l11 -= l12, (l11==ltemp1), TRUE);
  376.  
  377.   ltemp1 = CoolList<int>(5,11,66,111,33,55);
  378.   TEST_RUN("l11 ^= l12", l11 ^= l12, (l11==ltemp1), TRUE);
  379.  
  380.   l11 = CoolList<int>(12,1,55,3,88,77,44,33,22,11,66,2,3);
  381.   l12 = CoolList<int>(5,11,66,111,33,55);
  382.  
  383.   ltemp1 = CoolList<int>(4,55,33,11,66);
  384.   TEST_RUN("l13 = l11 & l12", l13 = l11 & l12, (l13==ltemp1), TRUE);
  385.  
  386.   ltemp1 = CoolList<int>(13,111,1,55,3,88,77,44,33,22,11,66,2,3);
  387.   TEST_RUN("l13 = l11 | l12", l13 = l11 | l12, (l13==ltemp1), TRUE);
  388.  
  389.   ltemp1 = CoolList<int>(8,1,3,88,77,44,22,2,3);
  390.   TEST_RUN("l13 = l11 - l12", l13 = l11 - l12, (l13==ltemp1), TRUE);
  391.  
  392.   ltemp1 = CoolList<int>(9,1,3,88,77,44,22,2,3,111);
  393.   TEST_RUN("l13 = l11 ^ l12", l13 = l11 ^ l12, (l13==ltemp1), TRUE);
  394. }
  395.  
  396. void list_int_set_test() {
  397.  
  398.   list_int_set_test1();
  399.   list_int_set_test2();
  400.   list_int_set_test3();
  401. }
  402.  
  403.  
  404.  
  405. void list_int_curpos_test1() {
  406.   CoolList<int> l1(3,11,22,33);
  407.   CoolList<int> ltemp1;
  408.  
  409.   TEST_RUN("l1.next()",l1.next(), l1.value(), 11);
  410.   
  411.   ltemp1 = CoolList<int>(4,11,55,22,33);
  412.   TEST_RUN("l1.insert_after(55)", l1.insert_after(55),
  413.        (l1.value()==55 && l1==ltemp1), TRUE);
  414.  
  415.   TEST_RUN("l1.prev()",l1.prev(),l1.value(), 11);
  416.  
  417.   ltemp1 = CoolList<int>(5,66,11,55,22,33);
  418.   TEST_RUN("l1.insert_before(66)", l1.insert_before(66), 
  419.        (l1.value()==66 && l1==ltemp1), TRUE);
  420.  
  421.   ltemp1 = CoolList<int>(4,11,55,22,33);
  422.   TEST("l1.remove()", (l1.remove()==66 && l1.value()==11 && l1==ltemp1), TRUE);
  423.  
  424.   ltemp1 = CoolList<int>(3,11,55,33);
  425.   TEST_RUN("l1.remove()", l1.next();l1.next(), 
  426.        (l1.remove()==22 && l1.value()==33 && l1==ltemp1), TRUE);
  427.  
  428.   TEST_RUN("l1.position()", l1.prev(), (l1.position()==1 && l1.value()==55),
  429.        TRUE);
  430. }
  431.  
  432. void list_int_curpos_test2() {
  433.   CoolList<int> l1(3,11,55,33);
  434.   CoolList<int> l2(4,55,66,33,22);
  435.   CoolList<int> ltemp1;
  436.  
  437.   TEST_RUN("l1.next_union(l2)", l1.reset(),
  438.        (l1.next_union(l2) && l1.value()==11), TRUE);
  439.   TEST_RUN("l1.next_union(l2)", l1.next_union(l2);l1.next_union(l2),
  440.        (l1.next_union(l2) && l1.value()==66), TRUE);
  441.   TEST("l1.next_union(l2)", (l1.next_union(l2) && l1.value()==22),TRUE);
  442.   TEST("l1.next_union(l2)", l1.next_union(l2), FALSE);
  443.  
  444.   TEST_RUN("l1.next_intersection(l2)", l1.reset(), 
  445.        (l1.next_intersection(l2) && l1.value()==55),  TRUE);
  446.   TEST("l1.next_intersection(l2)", 
  447.        (l1.next_intersection(l2) && l1.value()==33), TRUE);
  448.   TEST("l1.next_intersection(l2)", l1.next_intersection(l2), FALSE);
  449.   TEST_RUN("l1.next_difference(l2)", l1.reset(), 
  450.        (l1.next_difference(l2) && l1.value()==11), TRUE);
  451.   TEST("l1.next_difference(l2)", l1.next_difference(l2), FALSE);
  452.   l1.reset();
  453.   TEST_RUN("l1.next_xor(l2)", l1.reset(), 
  454.        (l1.next_xor(l2) && l1.value()==11), TRUE);
  455.   TEST_RUN("l1.next_xor(l2)", l1.next_xor(l2), 
  456.        (l1.next_xor(l2) && l1.value()==22), TRUE);
  457.   TEST("l1.next_xor(l2)", l1.next_xor(l2), FALSE);
  458. }
  459.  
  460. void list_int_currentpos_test() {
  461.   list_int_curpos_test1();
  462.   list_int_curpos_test2();
  463. }
  464.  
  465.  
  466.  
  467. void test_list_int() {
  468.  
  469.   cout << "\n*** Testing CoolList of Int ***\n\n";
  470.   list_int_op_test1();
  471.   list_int_op_test2();
  472.   list_int_op_test3();
  473.   list_int_op_test4();
  474.   list_int_set_test();
  475.   list_int_sort_test();
  476.   list_int_currentpos_test();
  477.   list_int_io_test();
  478. }
  479.  
  480.  
  481. // *********************
  482. // List of doubles tests
  483. // *********************
  484.  
  485. int my_compare_double(const double& t1, const double& t2) {
  486.   return ((t1 < t2) ? -1 : 1);
  487. }
  488.  
  489. void list_double_op_test1() {
  490.  
  491.   CoolList<double> ltemp1;
  492.   CoolList<double> ltemp2;
  493.  
  494.   // CoolList l0 is ().
  495.   CoolList<double> l0;
  496.   TEST("CoolList<double> l0", 1, 1);
  497.  
  498.   // CoolList l4(3,1.0,2.0,3.0) is (1.0 2.0 3.0).
  499.   CoolList<double> l4(3,1.0,2.0,3.0);
  500.   TEST("CoolList<double> l4(3,1.0,2.0,3.0)", 1, 1);
  501.  
  502.   // CoolList l5(l4) is (1.0 2.0 3.0).
  503.   CoolList<double> l5(l4);
  504.   TEST("CoolList<double> l5(l4)", 1, 1);
  505.  
  506.   TEST("l5[2]", l5[2]==3.0 && l5.value()==3.0, TRUE);
  507. //  TEST("l5[-1]", l5[-1], ERROR);
  508. //  TEST("l5[3]", l5[3], ERROR);
  509.   TEST("l5.get(1)", l5.get(1)==2.0, TRUE);
  510. //  l5[1]=43.0;
  511.   TEST_RUN("l5[1]=43.0", l5[1]=43.0, l5[1]==43.0, TRUE);
  512.   TEST_RUN("l5.put(55.0,1)", l5.put(55.0,1), l5.get(1)==55.0, TRUE);
  513.   // l5 is (1 55 3);
  514.   TEST_RUN("l5.tail(ltemp1)", l5.tail(ltemp1),
  515.        (ltemp1.length()==2 && ltemp1[0]==55.0 && ltemp1[1]==3.0), TRUE);
  516.   TEST_RUN("l5.tail(ltemp1,0)", l5.tail(ltemp1,0),
  517.        (ltemp1.length()==3 && ltemp1[0]==1.0 && ltemp1[1]==55.0
  518.         && ltemp1[2]==3.0),
  519.        TRUE);
  520.   TEST_RUN("l5.tail(ltemp1,3)", l5.tail(ltemp1,3), ltemp1.is_empty(), TRUE);
  521.   TEST_RUN("l5.tail(ltemp1,5)", l5.tail(ltemp1,5), ltemp1.is_empty(), TRUE);
  522.  
  523.   // l5 is (1 55 3);
  524.   TEST_RUN("l5.last(ltemp1,0)", l5.last(ltemp1,0), ltemp1.is_empty(), TRUE);
  525.   TEST_RUN("l5.last(ltemp1)", l5.last(ltemp1), 
  526.        (ltemp1.length()==1 && ltemp1[0]==3.0), TRUE);
  527.   TEST_RUN("l5.last(ltemp1,2)", l5.last(ltemp1,2),
  528.        (ltemp1.length()==2 && ltemp1[0]==55.0 && ltemp1[1]==3.0),
  529.        TRUE);
  530.   TEST_RUN("l5.last(ltemp1,3)", l5.last(ltemp1,3),
  531.        (ltemp1.length()==3 && ltemp1[0]==1.0 && ltemp1[1]==55.0
  532.         && ltemp1[2]==3.0),
  533.        TRUE);
  534.   TEST_RUN("l5.last(ltemp1,5)", l5.last(ltemp1,5), ltemp1.is_empty(), TRUE);
  535.  
  536. }
  537.  
  538. void list_double_op_test2() {
  539.  
  540.   CoolList<double> ltemp1;
  541.   CoolList<double> ltemp2;
  542.  
  543.   // CoolList l1(3.0) is (3.0).
  544.   CoolList<double> l1(3.0);
  545.   TEST("CoolList<double> l1(3.0)", 1, 1);
  546.  
  547.   // CoolList l2(2.0,l1) is (2.0 3.0).
  548.   CoolList<double> l2(2.0,l1);
  549.   TEST("CoolList<double> l2(2.0,l1)", 1, 1);
  550.  
  551.   // CoolList l3(1.0,l2) is (1.0 2.0 3.0).
  552.   CoolList<double> l3(1.0,l2);
  553.   TEST("CoolList<double> l3(1.0,l2)", 1, 1);
  554.  
  555.   // CoolList l4(3,1.0,2.0,3.0) is (1.0 2.0 3.0).
  556.   CoolList<double> l4(3,1.0,2.0,3.0);
  557.   TEST("CoolList<double> l4(3,1.0,2.0,3.0)", 1, 1);
  558.  
  559.   TEST("l3 == l4", l3==l4, TRUE);
  560.  
  561.   ltemp1 = CoolList<double>(4,11.0,22.0,33.0,44.0);
  562.   CoolList<double> l6;
  563.   
  564.   TEST_RUN("l6.but_last(ltemp2, 0)", l6.copy(ltemp1); l6.but_last(ltemp2, 0),
  565.        (ltemp2.length()==4 && ltemp2[0]==11.0 && ltemp2[1]==22.0
  566.         && ltemp2[2]==33.0 && ltemp2[3]==44.0),
  567.        TRUE);
  568.   
  569.   // l6 is (11 22 33 44)
  570.   TEST_RUN("l6.but_last(ltemp2)", l6.but_last(ltemp2),
  571.        (ltemp2.length()==3 && ltemp2[0]==11.0 && ltemp2[1]==22.0
  572.         && ltemp2[2]==33.0),
  573.        TRUE);
  574.   TEST_RUN("l6.but_last(ltemps2, 2)", l6.but_last(ltemp2, 2),
  575.        (ltemp2.length()==2 && ltemp2[0]==11.0 && ltemp2[1]==22.0),
  576.        TRUE);
  577.   TEST_RUN("l6.but_last(ltemp2, 4)", l6.but_last(ltemp2, 4), 
  578.        (ltemp2.length()==0), TRUE);
  579.   TEST_RUN("l6.but_last(ltemp2, 5)", l6.but_last(ltemp2, 5), 
  580.        (ltemp2.length()==0), TRUE);
  581.  
  582.   // l6 is now ()
  583.   TEST_RUN("l6.clear()", l6.clear(), (l6.length()==0), TRUE);
  584.  
  585.   TEST("l6.is_empty()", l6.is_empty(), TRUE);  // l6 is ();
  586.   TEST("l2.is_empty()", l2.is_empty(), FALSE); // l2 is (2 3)
  587.  
  588.   TEST("l6.length()", l6.length()==0, TRUE);   // l6 is ()
  589.   TEST("l3.length()", l3.length()== 3, TRUE);  // l3 is (1 2 3)
  590.  
  591.   // l6 is (11 22 33 44)
  592.   TEST_RUN("l6.position(33.0)", l6.copy(ltemp1),
  593.        (l6.position(33.0)==2 && l6.value()==33.0), TRUE);
  594.   TEST("l6.position(2.0)", l6.position(2.0)==-1, TRUE);
  595. }
  596.  
  597. void list_double_op_test3() {
  598.  
  599.   double temp;
  600.   CoolList<double> ltemp1;
  601.   CoolList<double> ltemp2;
  602.   
  603.   CoolList<double> l0;              // CoolList l0 is ().
  604.   CoolList<double> l1(3.0);              // CoolList l1 is (3.0).
  605.   CoolList<double> l2(2.0,l1);          // CoolList l2 is (2.0 3.0).
  606.   CoolList<double> l3(1.0,l2);          // CoolList l3 is (1.0 2.0 3.0).
  607.   CoolList<double> l4(3,1.0,55.0,3.0);      // CoolList l4 is (1.0 55.0 3.0).
  608.   CoolList<double> l5(l4);              // CoolList l5 is (1.0 2.0 3.0).
  609.   CoolList<double> l6(4,11.0,22.0,33.0,44.0); // CoolList l6 is (11.0 22.0 33.0 44.0).
  610.   CoolList<double> l9;
  611.  
  612.   TEST_RUN("l9.copy(l4)", l9.copy(l4), (l4==l9), TRUE);
  613.   TEST_RUN("l9 = l4", l9 = l4, (l4==l9), TRUE);
  614.  
  615.   // l6 is (11 22 33 44)
  616.   ltemp1 = CoolList<double>(4,44.0,33.0,22.0,11.0);
  617.   TEST_RUN("l6.reverse()", l6.reverse(), (l6==ltemp1), TRUE);
  618.  
  619.   // l6 is (44 33 22 11)
  620.   TEST_RUN("l6.push_end(66.0)", l6.push_end(66.0),
  621.        (l6.length()==5 && l6[4]==66.0 && l6.value()==66.0),
  622.        TRUE);
  623.   TEST_RUN("l6.push(77.0)", l6.push(77.0),
  624.        (l6.length()==6 && l6[0]==77.0 && l6.value()==77.0),
  625.        TRUE);
  626.   TEST_RUN("l6.push_new(88.0)", l6.push_new(88.0),
  627.        (l6.length()==7 && l6[0]==88.0 && l6.value()==88.0),
  628.        TRUE);
  629.   TEST_RUN("l6.push_new(22.0)", l6.push_new(22.0),
  630.        (l6.length()==7 && l6[0]==88.0), TRUE);
  631.   TEST("l6.pop()", (l6.pop(temp), temp), 88);
  632.  
  633.   // l6 is (77 44 33 22 11 66)
  634.   // l2 is (2 3)
  635.   // l4 is (1 55 3)
  636.  
  637.   // l6 is now (77 44 33 22 11 66 2 3)
  638.   TEST_RUN("l6.append(l2)", l6.append(l2),
  639.        (l6.value()==2.0 && l6.length()==8 && l6[6]==2.0 && l6[7]==3.0),
  640.        TRUE);
  641.  
  642.   // l6 is now (1 55 3 77 44 33 22 11 66 2 3)
  643.   TEST_RUN("l6.prepend(l4)", l6.prepend(l4),
  644.        (l6.value()==1.0 && l6.length()==11 && l6[0]==1.0 && l6[1]==55.0
  645.         && l6[2]==3.0),
  646.        TRUE);
  647.  
  648.   TEST_RUN("l6.set_tail(l2, 14)", ltemp1.copy(l6); l6.set_tail(l2,14),
  649.        l6==ltemp1, TRUE);
  650.   ltemp2 = CoolList<double>(6,1.0,55.0,3.0,77.0,2.0,3.0);
  651.   TEST_RUN("l6.set_tail(l2,4)", l6.set_tail(l2,4), 
  652.        (l6==ltemp2 && l6.value()==2.0), TRUE);
  653.   TEST_RUN("l6.set_tail(l2)", l6.set_tail(l2),
  654.        (l6.value()==2.0 && l6.length()==3 && l6[0]==1.0 && l6[1]==2.0
  655.         && l6[2]==3.0),
  656.        TRUE);
  657.   TEST_RUN("l6.set_tail(l2,0)", l6.set_tail(l2,0),
  658.        (l6.value()==2.0 && l6.length()==2 && l6[0]==2.0 && l6[1]==3.0),
  659.        TRUE);
  660. }
  661.  
  662. void list_double_op_test4() {
  663.  
  664.   CoolList<double> ltemp1;
  665.   CoolList<double> ltemp2;
  666.   CoolList<double> l8(5,11.0,22.0,33.0,44.0,55.0);
  667.   CoolList<double> l11(7,11.0,22.0,33.0,11.0,22.0,33.0,44.0);
  668.   
  669.   ltemp1 = CoolList<double>(4,44.0,33.0,22.0,11.0);
  670.  
  671.   ltemp2 = CoolList<double>(4,11.0,22.0,33.0,55.0);
  672.   TEST_RUN("l8.remove(77.0)", ltemp1.copy(l8); l8.remove(77.0),
  673.        (l8==ltemp1), TRUE);
  674.   TEST_RUN("l8.remove(44.0)", l8.remove(44.0),
  675.        (l8==ltemp2 && l8.value()==55.0), TRUE);
  676.  
  677.   ltemp1 = CoolList<double>(4,11.0,22.0,33.0,44.0);
  678.   TEST_RUN("l11.remove_duplicates()", l11.remove_duplicates(), (l11==ltemp1),
  679.        TRUE);
  680.  
  681.   // l8 is now (11 22 33 55)
  682.   ltemp2 = CoolList<double>(4,11.0,55.0,33.0,55.0);
  683.   TEST_RUN("l8.replace(66.0,22.0)", ltemp1.copy(l8); l8.replace(66.0,22.0),
  684.        (l8==ltemp1), TRUE);
  685.   TEST_RUN("l8.replace(22.0,55.0)", ltemp1.copy(l8); l8.replace(22.0,55.0),
  686.        (l8==ltemp2 && l8.value()==55.0), TRUE);
  687.  
  688.   ltemp2 = CoolList<double>(4,11.0,22.0,33.0,22.0);
  689.   TEST_RUN("l8.replace_all(66.0,22.0)",
  690.        ltemp1.copy(l8); l8.replace_all(66.0,22.0), 
  691.        (l8==ltemp1), TRUE);
  692.   TEST_RUN("l8.replace_all(55.0,22.0)",
  693.        ltemp1.copy(l8); l8.replace_all(55.0,22.0), 
  694.        (l8==ltemp2), TRUE);
  695.  
  696.   // l8 is now (11 22 33 22)
  697.   ltemp2 = CoolList<double>(5,11.0,22.0,111.0,33.0,22.0);
  698.   TEST_RUN("l8.insert_after(111.0,44.0)",
  699.        ltemp1.copy(l8); l8.insert_after(111.0,44.0), 
  700.        (l8==ltemp1), TRUE);
  701.   TEST_RUN("l8.insert_after(111.0,22.0)",
  702.        ltemp1.copy(l8); l8.insert_after(111.0,22.0), 
  703.        (l8==ltemp2 && l8.value()==111.0), TRUE);
  704.  
  705.   TEST_RUN("l8.insert_before(222.0,44.0)",
  706.        ltemp1.copy(l8); l8.insert_before(222.0,44.0), 
  707.        (l8==ltemp1), TRUE);
  708.   ltemp2 = CoolList<double>(6,11.0,222.0,22.0,111.0,33.0,22.0);
  709.   TEST_RUN("l8.insert_before(222.0,22.0)", l8.insert_before(222.0,22.0),
  710.        (l8==ltemp2 && l8.value()==222.0), TRUE);
  711.   ltemp2 = CoolList<double>(7,333.0,11.0,222.0,22.0,111.0,33.0,22.0);
  712.   TEST_RUN("l8.insert_before(333.0,11.0)", l8.insert_before(333.0,11.0),
  713.        (l8==ltemp2 && l8.value()==333.0), TRUE);
  714. }
  715.  
  716. void list_double_set_test1() {
  717.  
  718.   CoolList<double> ltemp1;
  719.   CoolList<double> l1;
  720.   CoolList<double> l2(4,11.0,22.0,33.0,44.0);
  721.   CoolList<double> l3(2,22.0,33.0);
  722.   CoolList<double> l4(5,11.0,22.0,33.0,44.0,55.0);
  723.   CoolList<double> l5(12,1.0,55.0,3.0,88.0,77.0,44.0,33.0,22.0,11.0,66.0,2.0,3.0);
  724.   CoolList<double> l6(5,11.0,66.0,111.0,33.0,55.0);
  725.  
  726.  
  727.   TEST("l2.find(33.0)", (l2.find(33.0) && l2.value()==33.0), TRUE);
  728.   TEST("l2.find(2.0)", l2.find(2.0), FALSE);
  729.  
  730.   TEST("l2.search(l3)", (l2.search(l3) && l2.value()==22.0), TRUE);
  731.   TEST("l2.search(l1)", l2.search(l1), FALSE);
  732.   TEST("l2.search(l4)", l2.search(l4), FALSE);
  733.   TEST("l4.search(l2)", (l4.search(l2) && l4.value()==11.0), TRUE);
  734.   TEST("l1.search(l2)", l1.search(l2), FALSE);
  735.  
  736.   TEST_RUN("l2.member(ltemp1, 22.0)", l2.member(ltemp1, 22.0),
  737.        (ltemp1.length()==3, ltemp1[0]==22.0 && ltemp1[1]==33.0,
  738.         ltemp1[2]==44.0 && l2.value()==22.0),
  739.        TRUE);
  740.   TEST_RUN("l2.member(ltemp1, 44.0)", l2.member(ltemp1, 44.0),
  741.        (ltemp1.length()==1 && ltemp1[0]==44.0 && l2.value()==44.0),
  742.        TRUE);
  743.   TEST_RUN("l2.member(ltemp1, 3.0)", l2.member(ltemp1, 3.0), 
  744.        (ltemp1.length()==0), TRUE);
  745.   TEST_RUN("l2.sublist(ltemp, l3)", l2.sublist(ltemp1, l3),
  746.        (ltemp1.length()==3 && ltemp1[0]==22.0, ltemp1[1]==33.0, 
  747.         ltemp1[2]==44.0 && l2.value()==22.0), 
  748.        TRUE);
  749.   TEST_RUN("l2.sublist(ltemp1, l1)", l2.sublist(ltemp1, l1),
  750.        (ltemp1.length()==0), TRUE);
  751.   TEST_RUN("l2.sublist(ltemp1, l4)", l2.sublist(ltemp1, l4), 
  752.        (ltemp1.length()==0), TRUE);
  753.   TEST_RUN("l4.sublist(ltemp1, l2)", l4.sublist(ltemp1, l2), 
  754.        (ltemp1==l4 && l4.value()==11.0), TRUE);
  755.   TEST_RUN("l1.sublist(ltemp1, l2)", l1.sublist(ltemp1, l2), 
  756.        (ltemp1.length()==0), TRUE);
  757.  
  758.   ltemp1 = CoolList<double>(4,55.0,33.0,11.0,66.0);
  759.   TEST_RUN("l5.set_intersection(l6)", l5.set_intersection(l6), (l5==ltemp1), TRUE);
  760.  
  761.   ltemp1 = CoolList<double>(5,111.0,55.0,33.0,11.0,66.0);
  762.   TEST_RUN("l5.set_union(l6)", l5.set_union(l6), (l5==ltemp1), TRUE);
  763.  
  764.   TEST_RUN("l5.set_difference(l6)", ltemp1.clear(); l5.set_difference(l6), 
  765.        (l5==ltemp1), TRUE);
  766.  
  767.   ltemp1 = CoolList<double>(5,11.0,66.0,111.0,33.0,55.0);
  768.   TEST_RUN("l5.set_xor(l6)", l5.set_xor(l6), (l5==ltemp1), TRUE);
  769.  
  770. }
  771.  
  772. void list_double_set_test2() {
  773.  
  774.   CoolList<double> ltemp1;
  775.   CoolList<double> l7(2,2.0,3.0);
  776.   CoolList<double> l8(3,1.0,2.0,3.0);
  777.   CoolList<double> l9 = l7 + l8;
  778.   CoolList<double> l10(3,4.0,5.0,6.0);
  779.   CoolList<double> l11(12,1.0,55.0,3.0,88.0,77.0,44.0,33.0,22.0,11.0,66.0,2.0,3.0);
  780.   CoolList<double> l12(5,11.0,66.0,111.0,33.0,55.0);
  781.   CoolList<double> l13;
  782.  
  783.   ltemp1 = CoolList<double>(5,2.0,3.0,1.0,2.0,3.0);
  784.   TEST("l9 = l7 + l8", (l9==ltemp1), TRUE);
  785.   ltemp1 = CoolList<double>(5,2.0,3.0,4.0,5.0,6.0);
  786.   TEST_RUN("l7 += l10", l7 += l10, (l7==ltemp1), TRUE);
  787.  
  788.   ltemp1 = CoolList<double>(4,55.0,33.0,11.0,66.0);
  789.   TEST_RUN("l11 &= l12", l11 &= l12, (l11==ltemp1), TRUE);
  790.  
  791.   ltemp1 = CoolList<double>(5,111.0,55.0,33.0,11.0,66.0);
  792.   TEST_RUN("l11 |= l12", l11 |= l12, (l11==ltemp1), TRUE);
  793.  
  794.   TEST_RUN("l11 -= l12", ltemp1.clear(); l11 -= l12, (l11==ltemp1), TRUE);
  795.  
  796.   ltemp1 = CoolList<double>(5,11.0,66.0,111.0,33.0,55.0);
  797.   TEST_RUN("l11 ^= l12", l11 ^= l12, (l11==ltemp1), TRUE);
  798.  
  799.   l11 = CoolList<double>(12,1.0,55.0,3.0,88.0,77.0,44.0,33.0,22.0,11.0,66.0,2.0,
  800.              3.0);
  801.   l12 = CoolList<double>(5,11.0,66.0,111.0,33.0,55.0);
  802.  
  803.   ltemp1 = CoolList<double>(4,55.0,33.0,11.0,66.0);
  804.   TEST_RUN("l13 = l11 & l12", l13 = l11 & l12, (l13==ltemp1), TRUE);
  805.  
  806.   ltemp1 = CoolList<double>(13,111.0,1.0,55.0,3.0,88.0,77.0,44.0,33.0,22.0,11.0,
  807.             66.0,2.0,3.0);
  808.   TEST_RUN("l13 = l11 | l12", l13 = l11 | l12, (l13==ltemp1), TRUE);
  809.  
  810.   ltemp1 = CoolList<double>(8,1.0,3.0,88.0,77.0,44.0,22.0,2.0,3.0);
  811.   TEST_RUN("l13 = l11 - l12", l13 = l11 - l12, (l13==ltemp1), TRUE);
  812.  
  813.   ltemp1 = CoolList<double>(9,1.0,3.0,88.0,77.0,44.0,22.0,2.0,3.0,111.0);
  814.   TEST_RUN("l13 = l11 ^ l12", l13 = l11 ^ l12, (l13==ltemp1), TRUE);
  815.  
  816. }
  817.  
  818. void list_double_sort_test() {
  819.  
  820.   CoolList<double> l1(4,6.0,66.0,22.0,222.0);
  821.   CoolList<double> l2(4,61.0,12.0,222.0,666.0);
  822.   CoolList<double> l3(4,7.0,51.0,77.0,24.0);
  823.   CoolList<double> ltemp1;
  824.  
  825.   ltemp1 = CoolList<double>(8,6.0,61.0,12.0,66.0,22.0,222.0,222.0,666.0);
  826.   TEST_RUN("l1.merge(l2,&my_compare_double)", l1.merge(l2,&my_compare_double), 
  827.        (l1==ltemp1), TRUE);
  828.  
  829.   ltemp1 = CoolList<double>(4,12.0,61.0,222.0,666.0);
  830.   TEST_RUN("l2.sort(&my_compare_double)", l2.sort(&my_compare_double), 
  831.        (l2==ltemp1), TRUE);
  832.  
  833.   ltemp1 = CoolList<double>(4,7.0,24.0,51.0,77.0);
  834.   TEST_RUN("l3.sort(&my_compare_double)", l3.sort(&my_compare_double),
  835.        (l3==ltemp1), TRUE);
  836.  
  837. }
  838.  
  839. void list_double_currentpos_test() {
  840.  
  841.   CoolList<double> l1(3,11.0,22.0,33.0);
  842.   CoolList<double> l2;
  843.   CoolList<double> ltemp1;
  844.  
  845.   TEST_RUN("l1.next()",l1.next(),l1.value(), 11.0);
  846.   
  847.   ltemp1 = CoolList<double>(4,11.0,55.0,22.0,33.0);
  848.   TEST_RUN("l1.insert_after(55.0)", l1.insert_after(55.0), 
  849.        (l1.value()==55.0 && l1==ltemp1), TRUE);
  850.  
  851.   TEST_RUN("l1.prev()",l1.prev(),l1.value(), 11.0);
  852.  
  853.   ltemp1 = CoolList<double>(5,66.0,11.0,55.0,22.0,33.0);
  854.   TEST_RUN("l1.insert_before(66.0)", l1.insert_before(66.0), 
  855.        (l1.value()==66.0 && l1==ltemp1), TRUE);
  856.  
  857.   ltemp1 = CoolList<double>(4,11.0,55.0,22.0,33.0);
  858.   TEST("l1.remove()", (l1.remove()==66.0 && l1.value()==11.0 && l1==ltemp1),
  859.         TRUE);
  860.  
  861.   ltemp1 = CoolList<double>(3,11.0,55.0,33.0);
  862.   TEST_RUN("l1.remove()", l1.next();l1.next(),
  863.        (l1.remove()==22.0 && l1.value()==33.0 && l1==ltemp1),
  864.        TRUE);
  865.  
  866.   TEST_RUN("l1.position()", l1.prev(), (l1.position()==1 && l1.value()==55.0),
  867.        TRUE);
  868.  
  869.   // l1 is (11.0,55.0,33.0)
  870.   l2 = CoolList<double>(4,55.0,66.0,33.0,22.0);
  871.  
  872.   TEST_RUN("l1.next_union(l2)", l1.reset(),
  873.        (l1.next_union(l2) && l1.value()==11.0), TRUE);
  874.   TEST_RUN("l1.next_union(l2)", l1.next_union(l2); l1.next_union(l2),
  875.        (l1.next_union(l2) && l1.value()==66.0),TRUE);
  876.   TEST("l1.next_union(l2)", (l1.next_union(l2) && l1.value()==22.0),TRUE);
  877.   TEST("l1.next_union(l2)", l1.next_union(l2), FALSE);
  878.  
  879.   TEST_RUN("l1.next_intersection(l2)", l1.reset(),
  880.        (l1.next_intersection(l2) && l1.value()==55.0),
  881.        TRUE);
  882.   TEST("l1.next_intersection(l2)", 
  883.        (l1.next_intersection(l2) && l1.value()==33.0),
  884.        TRUE);
  885.   TEST("l1.next_intersection(l2)", l1.next_intersection(l2), FALSE);
  886.   TEST_RUN("l1.next_difference(l2)", l1.reset(),
  887.        (l1.next_difference(l2) && l1.value()==11.0), 
  888.        TRUE);
  889.   TEST("l1.next_difference(l2)", l1.next_difference(l2), FALSE);
  890.   TEST_RUN("l1.next_xor(l2)", l1.reset(),
  891.        (l1.next_xor(l2) && l1.value()==11.0),
  892.        TRUE);
  893.   TEST_RUN("l1.next_xor(l2)", l1.next_xor(l2),
  894.        (l1.next_xor(l2) && l1.value()==22.0),
  895.        TRUE);
  896.   TEST("l1.next_xor(l2)", l1.next_xor(l2), FALSE);
  897. }
  898.  
  899. void list_double_io_test() {
  900.  
  901.   // ** an automated test would get input from file, rather than cin **
  902.   CoolList<double> input_list;
  903. //  cout << "\nTesting operator>> for CoolList<double>.";
  904. //  cout << "\nExample of CoolList<double> is (1 2 3).";
  905. //  cout << "\nPlease enter a CoolList<double> structure: ";
  906. //  cin >> input_list;
  907. //  cout << "\nInput_list is now set to: " << input_list << ".\n";
  908.  
  909. }
  910.  
  911. void test_list_double() {
  912.   cout << "\n*** Testing List of Double ***\n\n";
  913.   list_double_op_test1();
  914.   list_double_op_test2();
  915.   list_double_op_test3();
  916.   list_double_op_test4();
  917.   list_double_set_test1();
  918.   list_double_set_test2();
  919.   list_double_sort_test();
  920.   list_double_currentpos_test();
  921.   list_double_io_test();
  922.  
  923. }
  924.  
  925. // *******************
  926. // List of char* tests
  927. // *******************
  928.  
  929. void list_charp_op_test() {
  930.  
  931.   char* a = "a";
  932.   char* b = "b";
  933.   char* c = "c";
  934.   char* d = "d";
  935.   char* e = "e";
  936.  
  937.   CoolList<char*> l0;
  938.   TEST("CoolList<char*> l0", 1, 1);
  939.  
  940.   CoolList<char*> l1(c);
  941.   TEST("CoolList<char*> l1(c)", 1, 1);
  942.  
  943.   CoolList<char*> l2(b,l1);
  944.   TEST("CoolList<char*> l2(b,l1)", 1, 1);
  945.  
  946.   CoolList<char*> l3(a,l2);
  947.   TEST("CoolList<char*> l3(a,l2)", 1, 1);
  948.  
  949.   CoolList<char*> l4(3,a,b,c);
  950.   TEST("CoolList<char*> l4(3,a,b,c)", 1, 1);
  951.  
  952.   CoolList<char*> l5(l4);
  953.   TEST("CoolList<char*> l5(l4)", 1, 1);
  954.  
  955.   TEST("l3==l4", l3==l4, TRUE);
  956.   TEST_RUN("l4[2]=d", l4[2]=d, l4[2]==d, TRUE);
  957.  
  958. }
  959.  
  960. // *******************
  961. // List of char tests
  962. // *******************
  963.  
  964. void list_char_op_test() {
  965.  
  966.   char a = 'a';
  967.   char b = 'b';
  968.   char c = 'c';
  969.   char d = 'd';
  970.   char e = 'e';
  971.  
  972.   CoolList<char> l0;
  973.   TEST("CoolList<char> l0", 1, 1);
  974.  
  975.   CoolList<char> l1(c);
  976.   TEST("CoolList<char> l1(c)", 1, 1);
  977.  
  978.   CoolList<char> l2(b,l1);
  979.   TEST("CoolList<char> l2(b,l1)", 1, 1);
  980.  
  981.   CoolList<char> l3(a,l2);
  982.   TEST("CoolList<char> l3(a,l2)", 1, 1);
  983.  
  984. //  CoolList<char> l4(3,a,b,c);                 // char in ... will cause 
  985. //  TEST("CoolList<char> l4(3,a,b,c)", 1, 1);   // alignment error
  986.  
  987.   CoolList<char> l5(l3);
  988.   TEST("CoolList<char> l5(l3)", 1, 1);
  989.  
  990.   TEST("l3==l5", l3==l5, TRUE);
  991.   cout << l3 << &l5 << "\n";
  992.  
  993.   TEST_RUN("l5[2]=d", l5[2]=d, l5[2]==d, TRUE);
  994.  
  995. }
  996.  
  997. void test_list_chars() {
  998.   cout << "\n*** Testing List of Char* ***\n\n";
  999.   list_charp_op_test();
  1000.   cout << "\n*** Testing List of Char ***\n\n";
  1001.   list_char_op_test();
  1002.  
  1003. }
  1004.  
  1005. void test_list_vector() {
  1006.  
  1007.   cout << "\n*** Testing List of Vector of Int ***\n\n";
  1008.   CoolVector<int> v1(3,3,1,2,3);
  1009.   CoolVector<int> v2(3,3,1,2,3);
  1010.  
  1011.   CoolList<CoolVector<int> > l0;
  1012.   TEST("CoolList<CoolVector<int> > l0", l0.length()==0, TRUE);
  1013.  
  1014.   CoolList<CoolVector<int> > l1(v1);
  1015.   TEST("CoolList<CoolVector<int> > l1(v1)", (l1[0]==v1 && l1.length()==1), TRUE);
  1016.  
  1017.   CoolList<CoolVector<int>*> l2(2,&v1,&v2);
  1018.   TEST("CoolList<CoolVector<int>*> l2(2,&v1,&v2);", (l2[0]==&v1 && l2[1]==&v2), 1);
  1019.  
  1020. //  CoolList<CoolVector<int> > l3(2,v1,v2);   // canot pass vector in ...
  1021. //  TEST("CoolList<CoolVector<int> > l3(2,v1,v2);", (l3[0]==v1 && l3[1]==v2), 1);
  1022.  
  1023.   CoolList<CoolVector<int> > l3;
  1024.   l3.push(v1);
  1025.   l3.push_end(v2);
  1026.   TEST("CoolList<CoolVector<int> > l3(2,v1,v2);", (l3[0]==v1 && l3[1]==v2), 1);
  1027.   l3.push_end(v2);
  1028. }
  1029.  
  1030. void test_list_list() {
  1031.   cout << "\n*** Testing List of List ***\n\n";
  1032.   CoolList<int> l1(3,1,2,3);
  1033.  
  1034.   CoolList<CoolList<int> > l2(l1);
  1035.   TEST("CoolList<CoolList<int> > l2(l1)", (l2[0]==l1), 1);
  1036.  
  1037.   CoolList<CoolList<int>*> l4(&l1);
  1038.   TEST("CoolList<CoolList<int>*> l4(&l1)", (l4[0]==&l1), 1);
  1039.  
  1040.   CoolList<int>* l5 = &l1;
  1041.   CoolList<CoolList<int>*> l6(l5);
  1042.   TEST("CoolList<CoolList<int>*> l6(l5)", (l6[0]==&l1), 1);
  1043.  
  1044. //  CoolList<CoolList<int> > l3(2,l1,l1);  // canot pass list in ...
  1045. //  TEST("CoolList<CoolList<int> > l2(2,l1,l1)", (l2[0]==l1 && l2[1]==l1), 1);
  1046.  
  1047.   CoolList<CoolList<int> > l3;
  1048.   l3.push(l1);
  1049.   l3.push_end(l1);
  1050.   TEST("CoolList<CoolList<int> > l3(2,l1,l1)", (l3[0]==l1 && l3[1]==l1), 1);
  1051. }
  1052.  
  1053. void test_speed () {
  1054.   long n;
  1055.   for (n = 10; n <= 100000; n*=10) {    // length = 10, 100, 1000, 10000
  1056.     CoolTimer t;
  1057.     t.mark();
  1058.     {
  1059.       CoolList<int> l;
  1060.       for (int i = 0; i < n; i++) {
  1061.     l.push(i);
  1062.       }
  1063.     }
  1064.     cout << "Create and delete list of " << n << " elements took ";
  1065.     cout << t.real() << "milliseconds.\n";
  1066.   }
  1067.   for (n = 10000; n > 10; n/=10) {    // length = 10, 100, 1000, 10000
  1068.     CoolTimer t;
  1069.     t.mark();
  1070.     {
  1071.       CoolList<int> l;
  1072.       for (int i = 0; i < n; i++) {
  1073.     l.push(i);
  1074.       }
  1075.     }
  1076.     cout << "Create and delete list of " << n << " elements took ";
  1077.     cout << t.real() << "milliseconds.\n";
  1078.   }
  1079. }
  1080.  
  1081. void test_leak() { 
  1082.   for (;;) { 
  1083.     test_list_int(); 
  1084.     test_list_double();   
  1085.     test_list_chars() ;
  1086.     test_list_vector();
  1087.     test_list_list(); 
  1088.   } 
  1089. }
  1090.  
  1091. int main (void) {
  1092.   START("CoolList");
  1093.   test_list_int();
  1094.   test_list_double();
  1095.   test_list_chars();
  1096.   test_list_vector(); 
  1097.   test_list_list();
  1098. #if LEAK
  1099.   test_leak();
  1100. #endif
  1101. #if SPEED
  1102.   test_speed();
  1103. #endif
  1104.   SUMMARY();
  1105.   return 0;
  1106. }
  1107.  
  1108.